﻿using log4net;
using ServerCommon.Log;
using ServerCommon.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GatewayServer.Server
{
    public class NetNodeManagerInner : NetNodeManager
    {
        private static LogHelper log = LogHelper.GetLogger(typeof(NetNodeManagerInner));

        public override void OnRecv(ConnectionEventArgs e)
        {
            LogHelper.MarkSerialNumber();
            var proto = e.RecvedProtocol;
            NetNode node = dictIdNodes[e.NodeId];
            if (proto != null)
            {
                var performBegin = DateTime.Now.Ticks;

                if (e.RecvedProtocol != null)
                {
                    proto.OnProcess(node, e.Session);
                }
                else
                {
                    log.Debug("onRecv Error ");
                }

                var performSpan = DateTime.Now.Ticks - performBegin;
                if (performSpan > PERFORMACE_WARN_TIME)
                {
                    long ms = (long)(performSpan / TimeSpan.TicksPerMillisecond);
                    log.WarnFormat("OnProcess, performance warn,  ProtocolId:{0} spanTime:{1}ms ", e.RecvedProtocol.ProtocolId, ms);
                }
            }
            else
            {
                log.Debug("onRecv Error proto is null");
            }
        }
    }
}
